package com.limit.Controller;

import com.limit.annotation.SlidingWindowLimit;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.limit.enums.RateLimitStrategyEnum.IP;
import static com.limit.enums.RateLimitStrategyEnum.USER;

/**
 * @title: RateLimitController
 * @Author xu-xiang
 * @Date: 2024-3-23 14:23:17
 * @description: 请求限流测试
 */
@RestController
@RequestMapping("/limit")
//@TokenBucketLimit(bucketCapacity = 15, period = 5)
public class RateLimitController {

    //@TokenBucketLimit(bucketCapacity = 15, period = 5)
    //@LeakyBucketLimit(leakyCapacity = 5, dripRate = 1)
    @SlidingWindowLimit(maxRequestCount = 3, maxTimeInterval = 10, strategy = {IP, USER}) //每10秒最多请求3次
    @RequestMapping("/query")
    public Object query() {
        return "<h1 style='height:100%;width:100%;color: red'>请求成功</h1>";
    }

}
